package com.devin.controller;

import com.devin.model.entity.Live;
import com.devin.service.LiveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *  
 *  @author devin
 *  @date 2020-04-14 11:18
 *  @version 1.0.2
*/

@ResponseBody
@Slf4j
@Controller
public class LiveApi {

    private final LiveService liveService;

    @Autowired
    public LiveApi(LiveService liveService) {
        this.liveService = liveService;
    }


    /*
    * 返回直播列表
    * @Params 分页的对象参数
    * */
    @RequestMapping("/liveList")
    public Page<Live> getLiveList(@PageableDefault(size = 8,page = 0,sort = "id") Pageable pageable){
        log.info("返回直播列表");
        Page<Live> lives = liveService.listAll(pageable);
        return lives;
    }

    @RequestMapping("/getLiveById")
    public Live getLiveById(Long liveId){
        return this.liveService.getById(liveId);
    }
}
